package cn.hgj.util;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.atomic.AtomicInteger;

public class IdGenerator {
    private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
    private static final AtomicInteger SEQUENCE = new AtomicInteger(0);

    /**
     * 生成订单ID（格式：年月日时分秒+4位序列号）
     */
    public static String generateOrderId() {
        String timestamp = LocalDateTime.now().format(DATE_FORMAT);
        int seq = SEQUENCE.getAndIncrement() % 10000;
        return "O" + timestamp + String.format("%04d", seq);
    }
}
